<?php
class Accountsettings_Model_Accountsettingsdecision implements Accountsettings_Model_Mainable{
    
    private $action_handler;
    private $accountsettings_data_getstatus;
    private $accountsettings_data_getaccesslevels;
    private $core_controller_csrftoken;
    
    public function main(array $variables = null) {
        switch ($variables['get']['page']){
            case 'dodaj':
                return $this->add_new_account($variables);
                break;
            case "wstaw":
                return $this->insert_new_account($variables);
                break;
            case "edytuj":
                return $this->edit_user_account($variables);
                break;
            case "aktualizuj":
                return $this->update_user_account($variables);
                break;
            case "usun":
                return $this->delete_user_account($variables);
                break;
            default:
                return $this->default_action($variables);
                break;
        }
    }
    
    private function delete_user_account(array $variables = null){
        $this->action_handler = new Accountsettings_Model_Deleteaccountaction;
        return $this->action_handler->main($variables);
    }
    
    private function update_user_account(array $variables = null){
        $this->action_handler = new Accountsettings_Model_Updateaccountaction;
        return $this->action_handler->main($variables);
    }
    
    private function edit_user_account(array $variables = null){
        if(isset($variables['get']['name'])){
            $page['access_levels'] = $this->get_access_levels($variables);
            $page['statuses_list'] = $this->get_statuses_list($variables);
            $page['template'] = WEB_ROOT_FOLDER."accountsettings/views/add.php";
            $this->action_handler = new Accountsettings_Data_Getaccountdata;
            $page['content'] = $this->action_handler->main($variables);
            $this->core_controller_csrftoken = new Core_Controller_Csrftoken;
            $page['csrf_token'] = $this->core_controller_csrftoken->main($variables);
            return $page;
        }
        else {
            return $this->default_action($variables);
        }
    }
    
    private function insert_new_account(array $variable = null){
        $this->action_handler = new Accountsettings_Model_Insertaccountaction;
        return $this->action_handler->main($variable);
    }
    
    private function add_new_account(array $variables = null){
        $page['access_levels'] = $this->get_access_levels($variables);
        $page['statuses_list'] = $this->get_statuses_list($variables);
        $page['template'] = WEB_ROOT_FOLDER."accountsettings/views/add.php";
        $this->core_controller_csrftoken = new Core_Controller_Csrftoken;
        $page['csrf_token'] = $this->core_controller_csrftoken->main($variables);
        return $page;
    }
    
    private function default_action(array $variables = null){
        unset($variables);
        $this->action_handler = new Accountsettings_Model_Accountsettings;
        return $this->action_handler->main($variables);
    }
    
    private function get_statuses_list(array $variables = null){
        $this->accountsettings_data_getstatus = new Accountsettings_Data_Getstatus;
        return $this->accountsettings_data_getstatus->main($variables);
    }
    
    private function get_access_levels(array $variables = null){
        $this->accountsettings_data_getaccesslevels = new Accountsettings_Data_Getaccesslevels;
        return $this->accountsettings_data_getaccesslevels->main($variables);
    }

}
